package com.leha.forum.lehare.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leha.forum.lehare.entity.Category;
import com.leha.forum.lehare.service.CategoryService;
import com.leha.forum.lehare.mapper.CategoryMapper;
import org.springframework.stereotype.Service;

/**
* @author Administrator
* @description 针对表【category】的数据库操作Service实现
* @createDate 2025-04-15 21:44:28
*/
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
    implements CategoryService{

    @Override
    public boolean saveOrUpdateCategory(Category category) {
        if (category.getCategoryId() != null && category.getCategoryId() > 0) {
            Category existing = getById(category.getCategoryId());
            if (existing != null) {
                return updateById(category);
            } else {
                throw new IllegalStateException("分类" + category.getCategoryId() + "不存在");
            }
        } else {
            category.setCategoryId(null);
            return save(category);
        }
    }
}




